home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifSliderUI.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  174 lines

  1. /*
  2.  * @(#)MotifSliderUI.java    1.11 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.motif;
  22.  
  23. import java.awt.*;
  24.  
  25. import com.sun.java.swing.*;
  26. import com.sun.java.swing.event.*;
  27. import com.sun.java.swing.plaf.*;
  28.  
  29. import com.sun.java.swing.plaf.basic.BasicSliderUI;
  30.  
  31. /**
  32.  * Motif Slider
  33.  * <p>
  34.  * Warning: serialized objects of this class will not be compatible with
  35.  * future swing releases.  The current serialization support is appropriate
  36.  * for short term storage or RMI between Swing1.0 applications.  It will
  37.  * not be possible to load serialized Swing1.0 objects with future releases
  38.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  39.  * baseline for the serialized form of Swing objects.
  40.  *
  41.  * @version 1.11 02/02/98
  42.  * @author Jeff Dinkins
  43.  */
  44. public class MotifSliderUI extends BasicSliderUI
  45. {
  46.  
  47.     static final Dimension PREFERRED_HORIZONTAL_SIZE = new Dimension(164, 15);
  48.     static final Dimension PREFERRED_VERTICAL_SIZE = new Dimension(15, 164);
  49.  
  50.     static final Dimension MINIMUM_HORIZONTAL_SIZE = new Dimension(43, 15);
  51.     static final Dimension MINIMUM_VERTICAL_SIZE = new Dimension(15, 43);
  52.  
  53.     /**
  54.      * MotifSliderUI Constructor
  55.      */
  56.     public MotifSliderUI(JSlider b)   {
  57.     super(b);
  58.     }
  59.  
  60.     /**
  61.      * create a MotifSliderUI object
  62.      */
  63.     public static ComponentUI createUI(JComponent b)    {
  64.         return new MotifSliderUI((JSlider)b);
  65.     }
  66.  
  67.     public Dimension getPreferredHorizontalSize() {
  68.     return PREFERRED_HORIZONTAL_SIZE;
  69.     }
  70.  
  71.     public Dimension getPreferredVerticalSize() {
  72.     return PREFERRED_VERTICAL_SIZE;
  73.     }
  74.  
  75.     public Dimension getMinimumHorizontalSize() {
  76.     return MINIMUM_HORIZONTAL_SIZE;
  77.     }
  78.  
  79.     public Dimension getMinimumVerticalSize() {
  80.     return MINIMUM_VERTICAL_SIZE;
  81.     }
  82.  
  83.     /*
  84.     public int getTickSize() {
  85.     return 0;
  86.     }
  87.     */
  88.  
  89.     /*
  90.     public int getTickSpace() {
  91.     return 0;
  92.     }
  93.     */
  94.  
  95.     public void calculateThumbBounds()    {
  96.     if(slider.getOrientation() == JSlider.VERTICAL)    {
  97.         setThumbBounds(getScrollTrackRect().x,
  98.                yPositionForValue(slider.getValue()) - getThumbRect().height / 2,
  99.                getScrollTrackRect().width,
  100.                30);
  101.     } else {
  102.         setThumbBounds(xPositionForValue(slider.getValue()) - getThumbRect().width / 2,
  103.                getScrollTrackRect().y, 
  104.                30,
  105.                getScrollTrackRect().height);
  106.     }
  107.     }
  108.  
  109.  
  110.  
  111.     public void paintFocus(Graphics g)  {        
  112.     }
  113.  
  114.     public void paintTrack(Graphics g)  {        
  115.     }
  116.  
  117.     public void paintThumb(Graphics g)  {
  118.     Rectangle knobBounds = getThumbRect();
  119.         int x = knobBounds.x;
  120.         int y = knobBounds.y;        
  121.         int w = knobBounds.width;
  122.         int h = knobBounds.height;        
  123.         
  124.     if(slider.isEnabled()) {
  125.         g.setColor(slider.getForeground());
  126.     } else {
  127.         // PENDING(jeff) - the thumb should be dithered when disabled
  128.         g.setColor(slider.getForeground().darker());
  129.     }
  130.     
  131.     if (slider.getOrientation() == JSlider.HORIZONTAL ) {
  132.         g.translate(0, knobBounds.y-1);
  133.  
  134.         // fill
  135.         g.fillRect(x, 1, w, h - 1);
  136.  
  137.         // highlight
  138.         g.setColor(getHighlightColor());
  139.         g.drawLine(x, 1, x + w - 1, 1);             // top
  140.         g.drawLine(x, 1, x, h);                     // left
  141.         g.drawLine(x + w/2, 2, x + w/2, h-1);       // center
  142.  
  143.         // shadow
  144.         g.setColor(getShadowColor());
  145.         g.drawLine(x + 1, h, x + w - 1, h);         // bottom
  146.         g.drawLine(x + w - 1, 1, x + w - 1, h);     // right
  147.         g.drawLine(x + w/2 - 1, 2, x + w/2 - 1, h); // center
  148.  
  149.         g.translate(0, -(knobBounds.y-1));
  150.     } else {
  151.         g.translate(knobBounds.x-1, 0);
  152.  
  153.         // fill
  154.         g.fillRect(1, y, w - 1, h);
  155.  
  156.         // highlight
  157.         g.setColor(getHighlightColor());
  158.         g.drawLine(1, y, w, y);                     // top
  159.         g.drawLine(1, y+1, 1, y+h-1);               // left
  160.         g.drawLine(2, y+h/2, w-1, y+h/2);           // center
  161.  
  162.         // shadow
  163.         g.setColor(getShadowColor());
  164.         g.drawLine(2, y+h-1, w, y+h-1);             // bottom
  165.         g.drawLine(w, y+h-1, w, y);                 // right
  166.         g.drawLine(2, y+h/2-1, w-1, y+h/2-1);       // center
  167.  
  168.         g.translate(-(knobBounds.x-1), 0);
  169.     }
  170.     }
  171.     
  172. }
  173.  
  174.